package edu.neu.cs6515.xml;

import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.apache.commons.io.IOUtils;

/**
 * class to unmarshall edu.neu.cs6515.xml.Player
 */
public class XMLPlayerUnmarshaller {

    private final JAXBContext context;
    private final Unmarshaller unmarshaller;

    /**
     * C'tor
     */
    public XMLPlayerUnmarshaller() throws JAXBException {
        super();
        context = JAXBContext.newInstance(Player.class);
        unmarshaller = context.createUnmarshaller();
    }

    /**
     * 
     * @param input
     *            the xml string to be unmarshalled
     * @return player object
     */
    public Player unmarshall(final String input) throws JAXBException {
        final InputStream inputStream = IOUtils.toInputStream(input);
        return (Player) unmarshaller.unmarshal(inputStream);
    }

}
